package com.gxuwz.medical.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.gxuwz.medical.database.DbUtil;
import com.gxuwz.medical.domain.user.User;
import com.mysql.jdbc.PreparedStatement;

public class LoginDao {
	

	
	DbUtil Db = new DbUtil();
	private Connection conn = null;
	private PreparedStatement stmt = null;
	private ResultSet rs = null;
	
	public User login(String userid ) throws SQLException{
		User user = null;
		Connection conn = Db.getConn();
		try{
			String sql = "select * from User where userid='"+userid+"'";
			PreparedStatement stmt = (PreparedStatement) conn
					.prepareStatement(sql);
			rs = stmt.executeQuery(sql);
			
			if (rs.next()) {
				user = new User();
				
				user.setUserid(rs.getString("userid"));
				user.setPwd(rs.getString("pwd"));
				
				
				return user;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (stmt != null) {
					stmt.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return user;
		}
		
		
	



}


